/*+*****************************************************************************
 *
 * File Name          : test.c
 * Modification:
 * Author             : H.Zheng @ GZHU
 * @date              : 2023.04.02
 * Description        : a tutorial program to demonstrate simple task
                        on openharmony liteos-m
*******************************************************************************-*/

#include "simpleHAL.h"
#include "los_task.h"
#include "stdio.h"

//task1
static void TaskEntry1(void) {
	while (1)  {
		shalSetLed(LED0, LED_ON);
		LOS_Msleep(1000);
		shalSetLed(LED0, LED_OFF);
		LOS_Msleep(1000);  
		printf("hello\n");
	}
}	

//task2
static void TaskEntry2(void) {
	while (1)  {
		shalSetLed(LED1, LED_ON);
		LOS_Msleep(2500);
		shalSetLed(LED1, LED_OFF);
		LOS_Msleep(2500);  
		printf("hello\n");
	}
}	

int main(void) { 
	
	//init
	shalInitSysClock();
	shalInitLed();
	shalInitUart1();

	//init LOS
  LOS_KernelInit();	
	
  //start task 1
	unsigned int ret;
	unsigned int taskID1;
	TSK_INIT_PARAM_S task1 = { 0 };
	task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskEntry1;
	task1.uwStackSize  = 0x1000;
	task1.pcName       = "TaskEntry1";
	task1.usTaskPrio   = 6;
	ret = LOS_TaskCreate(&taskID1, &task1);
	if (ret != LOS_OK) {
	  shalSetLed(LED1, LED_ON);
	  while(1) {
		}
	}
  //start task 2
	unsigned int taskID2;
	TSK_INIT_PARAM_S task2 = { 0 };
	task2.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskEntry2;
	task2.uwStackSize  = 0x1000;
	task2.pcName       = "TaskEntry2";
	task2.usTaskPrio   = 6;
	ret = LOS_TaskCreate(&taskID2, &task2);
	if (ret != LOS_OK) {
	  shalSetLed(LED1, LED_ON);
	  while(1) {
		}
	}
	
	//start LOS
	LOS_Start();

//should never reach here.
	while(1){
	}

	return 0;
}
















